﻿using Ross.EntityFramework;
using Ross.Service;
using Ross.Service.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Http.Controllers;
using System.Web.Security;

namespace Ross.Traning.Controllers
{
    public class TraningController : BaseApiController
    {       
        [HttpPost]
        public JsonResult<ResultDto<Users>> Login([FromBody] LoginVM vm)
        {
            ResultDto<Users> result = new ResultDto<Users>();
            using (UserService serv = new UserService(dbContextStr))
            {
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(0, vm.username, DateTime.Now,
                            DateTime.Now.AddHours(1), true, string.Format("{0}&{1}", vm.username, vm.password),
                            FormsAuthentication.FormsCookiePath);
                string token = FormsAuthentication.Encrypt(ticket);
                result = serv.Login(vm, token);
            }            
            return Json(result);
        }

             
    }

}
